{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# jupyternotebook快捷键学习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 命令模式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- A 会在活跃单元之上插入一个新的单元，B 会在活跃单元之下插入一个新单元。\n",
    "- 连续按两次 D，可以删除一个单元。\n",
    "- 撤销被删除的单元，按 Z。\n",
    "- Y 会将当前活跃的单元变成一个代码单元。\n",
    "- 按住 Shift +上或下箭头可选择多个单元。在多选模式时，按住 Shift + M 可合并你的选择。\n",
    "- 按 F 会弹出「查找和替换」菜单。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 编辑模式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Ctrl + Home 到达单元起始位置。\n",
    "- Ctrl + S 保存进度。\n",
    "- 如之前提到的，Ctrl + Enter 会运行你的整个单元块。\n",
    "- Alt + Enter 不止会运行你的单元块，还会在下面添加一个新单元。\n",
    "- Ctrl + Shift + F 打开命令面板。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# [Bokeh学习](https://docs.bokeh.org)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Bokeh基础语法参考](https://blog.csdn.net/FlizhN/article/details/107415211)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 交互"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 平移工具在绘图内移动图形。\n",
    "* 框缩放工具放大绘图区域。(按住右键框选)\n",
    "* 通过鼠标滚轮进行放大和缩小。\n",
    "* 当前视图导出为 PNG 文件。\n",
    "* 将视图恢复为绘图的默认设置。\n",
    "* 了解有关 Bokeh 中可用工具的更多信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "若要数据展示在本页面（非打开新标签）\n",
    "可修改导入库部分代码为\n",
    "<br>from bokeh.plotting import figure, output_notebook, show\n",
    "<br>output_notebook() # 在notebook中显示\n",
    "<br>举例如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"2617\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"2617\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"2617\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"2617\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"2617\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"8f14569c-674b-4653-a9f6-9b0d94a053af\" data-root-id=\"2651\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"3ad3e6c3-8c9f-4f31-a36d-eb2a32e7ba67\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2660\"}],\"center\":[{\"id\":\"2663\"},{\"id\":\"2667\"},{\"id\":\"2696\"}],\"left\":[{\"id\":\"2664\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"2685\"}],\"title\":{\"id\":\"2688\"},\"toolbar\":{\"id\":\"2675\"},\"x_range\":{\"id\":\"2652\"},\"x_scale\":{\"id\":\"2656\"},\"y_range\":{\"id\":\"2654\"},\"y_scale\":{\"id\":\"2658\"}},\"id\":\"2651\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2668\"},{\"id\":\"2669\"},{\"id\":\"2670\"},{\"id\":\"2671\"},{\"id\":\"2672\"},{\"id\":\"2673\"}]},\"id\":\"2675\",\"type\":\"Toolbar\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2684\",\"type\":\"Line\"},{\"attributes\":{\"formatter\":{\"id\":\"2692\"},\"ticker\":{\"id\":\"2665\"}},\"id\":\"2664\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2665\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"2664\"},\"dimension\":1,\"ticker\":null},\"id\":\"2667\",\"type\":\"Grid\"},{\"attributes\":{\"items\":[{\"id\":\"2697\"}]},\"id\":\"2696\",\"type\":\"Legend\"},{\"attributes\":{\"text\":\"\"},\"id\":\"2688\",\"type\":\"Title\"},{\"attributes\":{\"data_source\":{\"id\":\"2682\"},\"glyph\":{\"id\":\"2683\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2684\"},\"selection_glyph\":null,\"view\":{\"id\":\"2686\"}},\"id\":\"2685\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2674\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2690\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2692\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2694\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2658\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"2660\"},\"ticker\":null},\"id\":\"2663\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2656\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2652\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2668\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2693\",\"type\":\"Selection\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[6,7,2,4,5]},\"selected\":{\"id\":\"2693\"},\"selection_policy\":{\"id\":\"2694\"}},\"id\":\"2682\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2672\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2674\"}},\"id\":\"2670\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"2682\"}},\"id\":\"2686\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"Temp.\"},\"renderers\":[{\"id\":\"2685\"}]},\"id\":\"2697\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2669\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"formatter\":{\"id\":\"2690\"},\"ticker\":{\"id\":\"2661\"}},\"id\":\"2660\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2683\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2661\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2671\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2673\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"2654\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"2651\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"3ad3e6c3-8c9f-4f31-a36d-eb2a32e7ba67\",\"root_ids\":[\"2651\"],\"roots\":{\"2651\":\"8f14569c-674b-4653-a9f6-9b0d94a053af\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2651"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#导入库\n",
    "from bokeh.plotting import figure, output_notebook, show\n",
    "output_notebook() # 在notebook中显示\n",
    "# 数据准备\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [6, 7, 2, 4, 5]\n",
    "\n",
    "# 创建一个带有标题和轴标签的plot\n",
    "p = figure(title=\"Simple line example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# 添加一个带有图例和线粗的线渲染器到绘图中\n",
    "p.line(x, y, legend_label=\"Temp.\", line_width=2)\n",
    "\n",
    "# 显示结果\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 简单折线图line（）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入库\n",
    "from bokeh.plotting import figure, show\n",
    "# 数据准备\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [6, 7, 2, 4, 5]\n",
    "\n",
    "# 创建一个带有标题和轴标签的plot\n",
    "p = figure(title=\"Simple line example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# 添加一个带有图例和线粗的线渲染器到绘图中\n",
    "p.line(x, y, legend_label=\"Temp.\", line_width=2)\n",
    "\n",
    "# 显示结果\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 简单折线图（组合）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y1 = [6, 7, 2, 4, 5]\n",
    "y2 = [2, 3, 4, 5, 6]\n",
    "y3 = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a title and axis labels\n",
    "p = figure(title=\"Multiple line example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# add multiple renderers\n",
    "p.line(x, y1, legend_label=\"Temp.\", color=\"blue\", line_width=2)\n",
    "p.line(x, y2, legend_label=\"Rate\", color=\"red\", line_width=2)\n",
    "p.line(x, y3, legend_label=\"Objects\", color=\"green\", line_width=2)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用circle()进行渲染"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y1 = [6, 7, 2, 4, 5]\n",
    "y2 = [2, 3, 4, 5, 6]\n",
    "y3 = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a title and axis labels\n",
    "p = figure(title=\"Multiple glyphs example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# add multiple renderers\n",
    "p.line(x, y1, legend_label=\"Temp.\", color=\"blue\", line_width=2)\n",
    "p.line(x, y2, legend_label=\"Rate\", color=\"red\", line_width=2)\n",
    "p.circle(x, y3, legend_label=\"Objects\", color=\"yellow\", size=12) # 圆\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用vbar()函数来渲染垂直条"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y1 = [6, 7, 2, 4, 5]\n",
    "y2 = [2, 3, 4, 5, 6]\n",
    "y3 = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a title and axis labels\n",
    "p = figure(title=\"Multiple glyphs example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# add multiple renderers\n",
    "p.line(x, y1, legend_label=\"Temp.\", color=\"blue\", line_width=2)\n",
    "p.vbar(x=x, top=y2, legend_label=\"Rate\", width=0.5, bottom=0, color=\"red\")\n",
    "p.circle(x, y3, legend_label=\"Objects\", color=\"yellow\", size=12)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义circle（）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- fill_color: 圆圈的填充颜色\n",
    "\n",
    "- fill_alpha：填充颜色的透明度（和之间的任何0 值1）\n",
    "\n",
    "- line_color: 圆圈轮廓的填充颜色\n",
    "\n",
    "- size：圆圈的大小（以屏幕单位或数据单位）\n",
    "\n",
    "- legend_label：圈子的图例条目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义circle（）+改变glyph举例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a title and axis labels\n",
    "p = figure(title=\"Glyphs properties example\", x_axis_label=\"x\", y_axis_label=\"y\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# add circle renderer with additional arguments\n",
    "circle = p.circle(\n",
    "    x,\n",
    "    y,\n",
    "    legend_label=\"Objects\",\n",
    "    fill_color=\"pink\",\n",
    "    fill_alpha=0.5,\n",
    "    line_color=\"red\",\n",
    "    size=60,\n",
    ")\n",
    "\n",
    "# change color of previously created object's glyph(利用glyph改变circle颜色，参数可调)\n",
    "glyph = circle.glyph\n",
    "glyph.fill_color = \"blue\"\n",
    "glyph.line_color=\"orange\"\n",
    "\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 添加图例、文本和注释"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 添加图例、文本和注释:使用Legend对象的属性来自定义图例。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y1 = [4, 5, 5, 7, 2]\n",
    "y2 = [2, 3, 4, 5, 6]\n",
    "\n",
    "# create a new plot\n",
    "p = figure(title=\"Legend example\")\n",
    "\n",
    "# 尺寸限制\n",
    "p = figure(plot_width=400,plot_height =400)\n",
    "\n",
    "# add circle renderer with legend_label arguments\n",
    "line = p.line(x, y1, legend_label=\"Temp.\", line_color=\"blue\", line_width=2)\n",
    "circle = p.circle(\n",
    "    x,\n",
    "    y2,\n",
    "    legend_label=\"Objects\",\n",
    "    fill_color=\"red\",\n",
    "    fill_alpha=0.5,\n",
    "    line_color=\"blue\",\n",
    "    size=80,\n",
    ")\n",
    "\n",
    "# display legend in top left corner (default is top right corner)\n",
    "p.legend.location = \"top_left\"\n",
    "\n",
    "# add a title to your legend\n",
    "p.legend.title = \"Obervations\"\n",
    "\n",
    "# change appearance of legend text\n",
    "p.legend.label_text_font = \"times\"\n",
    "p.legend.label_text_font_style = \"italic\"\n",
    "p.legend.label_text_color = \"navy\"\n",
    "\n",
    "# change border and background of legend\n",
    "p.legend.border_line_width = 3\n",
    "p.legend.border_line_color = \"navy\"\n",
    "p.legend.border_line_alpha = 0.8\n",
    "p.legend.background_fill_color = \"navy\"\n",
    "p.legend.background_fill_alpha = 0.2\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义标题：title参数传递给函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = figure(title=\"Headline example\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"224abe23-8850-4794-ba19-9f36c943e717\" data-root-id=\"2794\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"13092042-8160-4405-adee-fb54bbe6016c\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2805\"}],\"center\":[{\"id\":\"2808\"},{\"id\":\"2812\"},{\"id\":\"2840\"}],\"left\":[{\"id\":\"2809\"}],\"renderers\":[{\"id\":\"2830\"}],\"title\":{\"id\":\"2795\"},\"title_location\":\"left\",\"toolbar\":{\"id\":\"2820\"},\"x_range\":{\"id\":\"2797\"},\"x_scale\":{\"id\":\"2801\"},\"y_range\":{\"id\":\"2799\"},\"y_scale\":{\"id\":\"2803\"}},\"id\":\"2794\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2836\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2834\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[6,7,2,4,5]},\"selected\":{\"id\":\"2837\"},\"selection_policy\":{\"id\":\"2838\"}},\"id\":\"2827\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"items\":[{\"id\":\"2841\"}]},\"id\":\"2840\",\"type\":\"Legend\"},{\"attributes\":{\"align\":\"right\",\"background_fill_color\":\"darkgrey\",\"text\":\"Changing headline text example\",\"text_color\":{\"value\":\"white\"},\"text_font_size\":{\"value\":\"25px\"}},\"id\":\"2795\",\"type\":\"Title\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2819\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"2827\"},\"glyph\":{\"id\":\"2828\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2829\"},\"selection_glyph\":null,\"view\":{\"id\":\"2831\"}},\"id\":\"2830\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2797\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2806\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2813\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2799\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2837\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"2834\"},\"ticker\":{\"id\":\"2806\"}},\"id\":\"2805\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2803\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2838\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2801\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"2805\"},\"ticker\":null},\"id\":\"2808\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"2836\"},\"ticker\":{\"id\":\"2810\"}},\"id\":\"2809\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2810\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"2809\"},\"dimension\":1,\"ticker\":null},\"id\":\"2812\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"value\":\"Temp.\"},\"renderers\":[{\"id\":\"2830\"}]},\"id\":\"2841\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2814\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2813\"},{\"id\":\"2814\"},{\"id\":\"2815\"},{\"id\":\"2816\"},{\"id\":\"2817\"},{\"id\":\"2818\"}]},\"id\":\"2820\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2818\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2819\"}},\"id\":\"2815\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2816\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2817\",\"type\":\"ResetTool\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2829\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2828\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"2827\"}},\"id\":\"2831\",\"type\":\"CDSView\"}],\"root_ids\":[\"2794\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"13092042-8160-4405-adee-fb54bbe6016c\",\"root_ids\":[\"2794\"],\"roots\":{\"2794\":\"224abe23-8850-4794-ba19-9f36c943e717\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2794"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [6, 7, 2, 4, 5]\n",
    "\n",
    "# create new plot\n",
    "p = figure(title=\"Headline example\")\n",
    "\n",
    "# add line renderer with a legend\n",
    "p.line(x, y, legend_label=\"Temp.\", line_width=2)\n",
    "\n",
    "# change headline location to the left\n",
    "p.title_location = \"left\"\n",
    "\n",
    "# change headline text\n",
    "p.title.text = \"Changing headline text example\"\n",
    "\n",
    "# style the headline\n",
    "p.title.text_font_size = \"25px\"\n",
    "p.title.align = \"right\"\n",
    "p.title.background_fill_color = \"darkgrey\"\n",
    "p.title.text_color = \"white\"\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 注释的使用（将带阴影的矩形区域渲染为注释。）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "首先需要 BoxAnnotation从bokeh.models导入类："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import BoxAnnotation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接下来，创建BoxAnnotation对象。（如果不传递 bottom or top，Bokeh 会自动将框的尺寸扩展到绘图的边缘：）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "low_box = BoxAnnotation(top=20, fill_alpha=0.2, fill_color=\"red\")  # fill_alpha为透明度\n",
    "mid_box = BoxAnnotation(bottom=20, top=80, fill_alpha=0.2, fill_color=\"blue\")\n",
    "high_box = BoxAnnotation(bottom=80, fill_alpha=0.2, fill_color=\"red\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最后，将BoxAnnotation对象添加到现有图形中。使用add_layout()方法添加你的盒子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "p.add_layout(low_box)\n",
    "p.add_layout(mid_box)\n",
    "p.add_layout(high_box)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"877b8a7d-b1ce-493e-a1e5-30e9c660f3ff\" data-root-id=\"4314\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"9b9a9e85-7600-43ee-94d6-6e90faa5b813\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"4325\"}],\"center\":[{\"id\":\"4328\"},{\"id\":\"4332\"},{\"id\":\"4352\"},{\"id\":\"4353\"},{\"id\":\"4354\"}],\"left\":[{\"id\":\"4329\"}],\"renderers\":[{\"id\":\"4350\"}],\"title\":{\"id\":\"4315\"},\"toolbar\":{\"id\":\"4340\"},\"x_range\":{\"id\":\"4317\"},\"x_scale\":{\"id\":\"4321\"},\"y_range\":{\"id\":\"4319\"},\"y_scale\":{\"id\":\"4323\"}},\"id\":\"4314\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"Box annotation example\"},\"id\":\"4315\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"4338\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"4450\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"4326\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"4334\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"4319\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"4333\"},{\"id\":\"4334\"},{\"id\":\"4335\"},{\"id\":\"4336\"},{\"id\":\"4337\"},{\"id\":\"4338\"}]},\"id\":\"4340\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"4333\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom\":80,\"fill_alpha\":0.2,\"fill_color\":\"red\"},\"id\":\"4354\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"4339\"}},\"id\":\"4335\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"4325\"},\"ticker\":null},\"id\":\"4328\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"4336\",\"type\":\"SaveTool\"},{\"attributes\":{\"formatter\":{\"id\":\"4448\"},\"ticker\":{\"id\":\"4330\"}},\"id\":\"4329\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#000000\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"4349\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"4337\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"4446\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"line_color\":\"#000000\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"4348\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"4347\"}},\"id\":\"4351\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"4323\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"4446\"},\"ticker\":{\"id\":\"4326\"}},\"id\":\"4325\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"4329\"},\"dimension\":1,\"ticker\":null},\"id\":\"4332\",\"type\":\"Grid\"},{\"attributes\":{\"bottom\":20,\"fill_alpha\":0.2,\"fill_color\":\"blue\",\"top\":80},\"id\":\"4353\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"4448\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"4449\",\"type\":\"Selection\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"4339\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"4347\"},\"glyph\":{\"id\":\"4348\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"4349\"},\"selection_glyph\":null,\"view\":{\"id\":\"4351\"}},\"id\":\"4350\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50],\"y\":[93,50,21,64,38,71,54,28,99,17,55,41,76,88,9,3,35,80,30,84,14,32,37,72,62,48,96,44,57,60,52,79,58,16,31,8,47,69,97,45,86,51,6,70,56,59,63,39,12,81,74]},\"selected\":{\"id\":\"4449\"},\"selection_policy\":{\"id\":\"4450\"}},\"id\":\"4347\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"4330\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":0.2,\"fill_color\":\"red\",\"top\":20},\"id\":\"4352\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"4321\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"4317\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"4314\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"9b9a9e85-7600-43ee-94d6-6e90faa5b813\",\"root_ids\":[\"4314\"],\"roots\":{\"4314\":\"877b8a7d-b1ce-493e-a1e5-30e9c660f3ff\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "4314"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "from bokeh.models import BoxAnnotation\n",
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# generate some data (1-50 for x, random values for y)\n",
    "x = list(range(0, 51))\n",
    "y = random.sample(range(0, 100), 51)\n",
    "\n",
    "# create new plot\n",
    "p = figure(title=\"Box annotation example\")\n",
    "\n",
    "# add line renderer\n",
    "line = p.line(x, y, line_color=\"#000000\", line_width=2)\n",
    "\n",
    "# add box annotations\n",
    "low_box = BoxAnnotation(top=20, fill_alpha=0.2, fill_color=\"red\")\n",
    "mid_box = BoxAnnotation(bottom=20, top=80, fill_alpha=0.2, fill_color=\"blue\")\n",
    "high_box = BoxAnnotation(bottom=80, fill_alpha=0.2, fill_color=\"red\")\n",
    "\n",
    "# add boxes to existing figure\n",
    "p.add_layout(low_box)\n",
    "p.add_layout(mid_box)\n",
    "p.add_layout(high_box)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 自定义情节"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用主题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bokeh 带有五个内置主题：caliber、 dark_minimal、light_minimal、night_sky和contrast。\n",
    "<br>要使用其中一个内置主题，请将要使用的主题的名称分配给theme"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"20c12983-b1b3-4c84-bbd9-131216d34bef\" data-root-id=\"5573\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"303a0573-4a81-439c-b749-fea9004e62e9\":{\"roots\":{\"references\":[{\"attributes\":{\"background_fill_color\":\"#000000\",\"below\":[{\"id\":\"5582\"}],\"border_fill_color\":\"#FFFFFF\",\"center\":[{\"id\":\"5585\"},{\"id\":\"5589\"}],\"left\":[{\"id\":\"5586\"}],\"max_width\":500,\"outline_line_alpha\":0.25,\"outline_line_color\":\"#000000\",\"plot_height\":250,\"renderers\":[{\"id\":\"5607\"}],\"sizing_mode\":\"stretch_width\",\"title\":{\"id\":\"5752\"},\"toolbar\":{\"id\":\"5597\"},\"x_range\":{\"id\":\"5574\"},\"x_scale\":{\"id\":\"5578\"},\"y_range\":{\"id\":\"5576\"},\"y_scale\":{\"id\":\"5580\"}},\"id\":\"5573\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"5578\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"5596\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"5754\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"5586\"},\"dimension\":1,\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"5589\",\"type\":\"Grid\"},{\"attributes\":{\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"5756\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"5587\"}},\"id\":\"5586\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"5756\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"5583\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"5574\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"5582\"},\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"5585\",\"type\":\"Grid\"},{\"attributes\":{\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"5754\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"5583\"}},\"id\":\"5582\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"5604\"},\"glyph\":{\"id\":\"5605\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"5606\"},\"selection_glyph\":null,\"view\":{\"id\":\"5608\"}},\"id\":\"5607\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"5580\",\"type\":\"LinearScale\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[4,5,5,7,2]},\"selected\":{\"id\":\"5757\"},\"selection_policy\":{\"id\":\"5758\"}},\"id\":\"5604\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"5590\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"5591\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"5606\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"5595\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"5757\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"5590\"},{\"id\":\"5591\"},{\"id\":\"5592\"},{\"id\":\"5593\"},{\"id\":\"5594\"},{\"id\":\"5595\"}]},\"id\":\"5597\",\"type\":\"Toolbar\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"5605\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"5758\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"5604\"}},\"id\":\"5608\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"5593\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"5594\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"5576\",\"type\":\"DataRange1d\"},{\"attributes\":{\"overlay\":{\"id\":\"5596\"}},\"id\":\"5592\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\",\"text_color\":{\"value\":\"#000000\"},\"text_font\":\"Helvetica\",\"text_font_size\":{\"value\":\"1.15em\"}},\"id\":\"5752\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"5587\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"5573\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"303a0573-4a81-439c-b749-fea9004e62e9\",\"root_ids\":[\"5573\"],\"roots\":{\"5573\":\"20c12983-b1b3-4c84-bbd9-131216d34bef\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "5573"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.io import curdoc #先引入\n",
    "\n",
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# apply theme to current document\n",
    "curdoc().theme = \"contrast\"   #书写\n",
    "\n",
    "# create a plot\n",
    "p = figure(sizing_mode=\"stretch_width\", max_width=500, height=250)\n",
    "\n",
    "# add a renderer\n",
    "p.line(x, y)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用主题（调整外观）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置宽度和高度【使用属性width和height在figure中()】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"96a3ff40-5a2c-4297-a937-a5f25c55ad39\" data-root-id=\"5814\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"62d918d5-f291-43c7-971f-92076648140d\":{\"roots\":{\"references\":[{\"attributes\":{\"background_fill_color\":\"#000000\",\"below\":[{\"id\":\"5825\"}],\"border_fill_color\":\"#FFFFFF\",\"center\":[{\"id\":\"5828\"},{\"id\":\"5832\"}],\"left\":[{\"id\":\"5829\"}],\"outline_line_alpha\":0.25,\"outline_line_color\":\"#000000\",\"plot_height\":250,\"plot_width\":350,\"renderers\":[{\"id\":\"5850\"}],\"title\":{\"id\":\"5815\"},\"toolbar\":{\"id\":\"5840\"},\"x_range\":{\"id\":\"5817\"},\"x_scale\":{\"id\":\"5821\"},\"y_range\":{\"id\":\"5819\"},\"y_scale\":{\"id\":\"5823\"}},\"id\":\"5814\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"6009\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[4,5,5,7,2]},\"selected\":{\"id\":\"6008\"},\"selection_policy\":{\"id\":\"6009\"}},\"id\":\"5847\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"6005\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"5848\",\"type\":\"Circle\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"5839\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"text\":\"Plot sizing example\",\"text_color\":{\"value\":\"#000000\"},\"text_font\":\"Helvetica\",\"text_font_size\":{\"value\":\"1.15em\"}},\"id\":\"5815\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"6007\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"5817\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"5826\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"y\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6007\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"5830\"}},\"id\":\"5829\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis_label\":\"x\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6005\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"5826\"}},\"id\":\"5825\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"5830\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"5823\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"5819\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"5821\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"5825\"},\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"5828\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"5829\"},\"dimension\":1,\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"5832\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"5834\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"5849\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"5833\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"6008\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"5833\"},{\"id\":\"5834\"},{\"id\":\"5835\"},{\"id\":\"5836\"},{\"id\":\"5837\"},{\"id\":\"5838\"}]},\"id\":\"5840\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"5838\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"5839\"}},\"id\":\"5835\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"5836\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"5837\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"5847\"},\"glyph\":{\"id\":\"5848\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"5849\"},\"selection_glyph\":null,\"view\":{\"id\":\"5851\"}},\"id\":\"5850\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"5847\"}},\"id\":\"5851\",\"type\":\"CDSView\"}],\"root_ids\":[\"5814\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"62d918d5-f291-43c7-971f-92076648140d\",\"root_ids\":[\"5814\"],\"roots\":{\"5814\":\"96a3ff40-5a2c-4297-a937-a5f25c55ad39\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "5814"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a specific size\n",
    "p = figure(\n",
    "    title=\"Plot sizing example\",\n",
    "    \n",
    "    \n",
    "    width=350,\n",
    "    height=250,\n",
    "    \n",
    "    \n",
    "    x_axis_label=\"x\",\n",
    "    y_axis_label=\"y\",\n",
    ")\n",
    "\n",
    "# add circle renderer\n",
    "circle = p.circle(x, y, fill_color=\"red\", size=15)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 与更改现有 glyph 的设计类似，您可以在创建绘图后随时更改其属性："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "p.width = 450\n",
    "p.height = 150"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"2e0c297f-27ef-49f6-b9c6-961d218041fd\" data-root-id=\"6059\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"c2f58a49-999f-43b3-8b50-a52aea7920a4\":{\"roots\":{\"references\":[{\"attributes\":{\"background_fill_color\":\"#000000\",\"below\":[{\"id\":\"6070\"}],\"border_fill_color\":\"#FFFFFF\",\"center\":[{\"id\":\"6073\"},{\"id\":\"6077\"}],\"height\":150,\"left\":[{\"id\":\"6074\"}],\"outline_line_alpha\":0.25,\"outline_line_color\":\"#000000\",\"plot_height\":250,\"plot_width\":350,\"renderers\":[{\"id\":\"6095\"}],\"title\":{\"id\":\"6060\"},\"toolbar\":{\"id\":\"6085\"},\"width\":450,\"x_range\":{\"id\":\"6062\"},\"x_scale\":{\"id\":\"6066\"},\"y_range\":{\"id\":\"6064\"},\"y_scale\":{\"id\":\"6068\"}},\"id\":\"6059\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"6066\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6081\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"6078\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"6084\"}},\"id\":\"6080\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"6258\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"6084\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"6261\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"6262\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"6260\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"6082\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"6075\",\"type\":\"BasicTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"6078\"},{\"id\":\"6079\"},{\"id\":\"6080\"},{\"id\":\"6081\"},{\"id\":\"6082\"},{\"id\":\"6083\"}]},\"id\":\"6085\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"6071\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[4,5,5,7,2]},\"selected\":{\"id\":\"6261\"},\"selection_policy\":{\"id\":\"6262\"}},\"id\":\"6092\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data_source\":{\"id\":\"6092\"},\"glyph\":{\"id\":\"6093\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6094\"},\"selection_glyph\":null,\"view\":{\"id\":\"6096\"}},\"id\":\"6095\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"6074\"},\"dimension\":1,\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"6077\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"6093\",\"type\":\"Circle\"},{\"attributes\":{\"source\":{\"id\":\"6092\"}},\"id\":\"6096\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"6070\"},\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"6073\",\"type\":\"Grid\"},{\"attributes\":{\"axis_label\":\"y\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6260\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"6075\"}},\"id\":\"6074\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6083\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"6068\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6079\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"text\":\"Plot resizing example\",\"text_color\":{\"value\":\"#000000\"},\"text_font\":\"Helvetica\",\"text_font_size\":{\"value\":\"1.15em\"}},\"id\":\"6060\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"6094\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"6062\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis_label\":\"x\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6258\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"6071\"}},\"id\":\"6070\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6064\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"6059\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"c2f58a49-999f-43b3-8b50-a52aea7920a4\",\"root_ids\":[\"6059\"],\"roots\":{\"6059\":\"2e0c297f-27ef-49f6-b9c6-961d218041fd\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "6059"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with a specific size\n",
    "p = figure(\n",
    "    title=\"Plot resizing example\",\n",
    "    width=350,\n",
    "    height=250,\n",
    "    x_axis_label=\"x\",\n",
    "    y_axis_label=\"y\",\n",
    ")\n",
    "\n",
    "# chage plot size\n",
    "p.width = 450\n",
    "p.height = 150\n",
    "\n",
    "# add circle renderer\n",
    "circle = p.circle(x, y, fill_color=\"red\", size=15)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 响应式设置"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用属性sizing_mode\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "    sizing_mode=\"stretch_width\",\n",
    "    height=250,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"85018b70-39ac-493b-a95b-842d9c3d0431\" data-root-id=\"6312\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5abbf0a6-e3a6-4fb6-87a6-39e2bda8a564\":{\"roots\":{\"references\":[{\"attributes\":{\"background_fill_color\":\"#000000\",\"below\":[{\"id\":\"6323\"}],\"border_fill_color\":\"#FFFFFF\",\"center\":[{\"id\":\"6326\"},{\"id\":\"6330\"}],\"left\":[{\"id\":\"6327\"}],\"outline_line_alpha\":0.25,\"outline_line_color\":\"#000000\",\"plot_height\":250,\"renderers\":[{\"id\":\"6348\"}],\"sizing_mode\":\"stretch_width\",\"title\":{\"id\":\"6313\"},\"toolbar\":{\"id\":\"6338\"},\"x_range\":{\"id\":\"6315\"},\"x_scale\":{\"id\":\"6319\"},\"y_range\":{\"id\":\"6317\"},\"y_scale\":{\"id\":\"6321\"}},\"id\":\"6312\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"6324\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"y\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6521\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"6328\"}},\"id\":\"6327\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"6317\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"6319\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"6328\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"6321\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis_label\":\"x\",\"axis_label_standoff\":10,\"axis_label_text_color\":\"#000000\",\"axis_label_text_font\":\"Helvetica\",\"axis_label_text_font_size\":\"1.25em\",\"axis_label_text_font_style\":\"normal\",\"axis_line_alpha\":0,\"axis_line_color\":\"#000000\",\"formatter\":{\"id\":\"6519\"},\"major_label_text_color\":\"#000000\",\"major_label_text_font\":\"Helvetica\",\"major_label_text_font_size\":\"1.025em\",\"major_tick_line_alpha\":0,\"major_tick_line_color\":\"#000000\",\"minor_tick_line_alpha\":0,\"minor_tick_line_color\":\"#000000\",\"ticker\":{\"id\":\"6324\"}},\"id\":\"6323\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5],\"y\":[4,5,5,7,2]},\"selected\":{\"id\":\"6522\"},\"selection_policy\":{\"id\":\"6523\"}},\"id\":\"6345\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"6323\"},\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"6326\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"6327\"},\"dimension\":1,\"grid_line_alpha\":0.25,\"grid_line_color\":\"#E0E0E0\",\"ticker\":null},\"id\":\"6330\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"6332\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"6347\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"6331\",\"type\":\"PanTool\"},{\"attributes\":{\"text\":\"Plot responsive sizing example\",\"text_color\":{\"value\":\"#000000\"},\"text_font\":\"Helvetica\",\"text_font_size\":{\"value\":\"1.15em\"}},\"id\":\"6313\",\"type\":\"Title\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"6331\"},{\"id\":\"6332\"},{\"id\":\"6333\"},{\"id\":\"6334\"},{\"id\":\"6335\"},{\"id\":\"6336\"}]},\"id\":\"6338\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"6336\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"6522\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"6337\"}},\"id\":\"6333\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"6334\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"6335\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"6345\"},\"glyph\":{\"id\":\"6346\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"6347\"},\"selection_glyph\":null,\"view\":{\"id\":\"6349\"}},\"id\":\"6348\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"6523\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"6345\"}},\"id\":\"6349\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"6315\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"6519\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"6337\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":15},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"6346\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"6521\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"6312\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5abbf0a6-e3a6-4fb6-87a6-39e2bda8a564\",\"root_ids\":[\"6312\"],\"roots\":{\"6312\":\"85018b70-39ac-493b-a95b-842d9c3d0431\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "6312"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a new plot with responsive width\n",
    "p = figure(\n",
    "    title=\"Plot responsive sizing example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    height=250,\n",
    "    x_axis_label=\"x\",\n",
    "    y_axis_label=\"y\",\n",
    ")\n",
    "\n",
    "# add circle renderer\n",
    "circle = p.circle(x, y, fill_color=\"red\", size=15)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义轴"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置轴的外观"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 为轴设置标签\n",
    "\n",
    "- 为您的坐标区显示的数字设置样式\n",
    "\n",
    "- 为轴本身定义颜色和其他布局属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a plot\n",
    "p = figure(\n",
    "    title=\"Customized axes example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=350,\n",
    ")\n",
    "\n",
    "# add a renderer\n",
    "p.circle(x, y, size=10)\n",
    "\n",
    "# change some things about the x-axis\n",
    "p.xaxis.axis_label = \"Temp\"\n",
    "p.xaxis.axis_line_width = 3\n",
    "p.xaxis.axis_line_color = \"red\"\n",
    "\n",
    "# change some things about the y-axis\n",
    "p.yaxis.axis_label = \"Pressure\"\n",
    "p.yaxis.major_label_text_color = \"orange\"\n",
    "p.yaxis.major_label_orientation = \"vertical\"\n",
    "\n",
    "# change things on all axes\n",
    "p.axis.minor_tick_in = -3 # 刻度往绘图区域内延伸长度(Y轴)\n",
    "p.axis.minor_tick_out = 6 # 刻度往绘图区域外延伸长度(X轴)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 定义轴范围"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为绘图绘制轴时，Bokeh 会自动确定每个轴需要覆盖的范围，以便显示所有值。\n",
    "<br>例如，如果 y 轴上的值介于 2 和 17 之间，Bokeh 会自动创建一个 y 轴，范围从略低于 2 到略高于 17。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "手动定义轴的范围-使用y_range()函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [2, 5, 5, 7, 17]\n",
    "\n",
    "# create a new plot with responsive width\n",
    "p = figure(\n",
    "    y_range=(0, 25),\n",
    "    title=\"Axis range example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# add circle renderer with additional arguments\n",
    "circle = p.circle(x, y, size=8)\n",
    "\n",
    "# show the results\n",
    "show(p)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 格式化轴刻度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用这些格式化程序在 y 轴上显示货币符号---TickFormatter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "要在 y 轴上显示美元金额而不仅仅是数字，请使用 NumeralTickFormatter："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "首先，NumeralTickFormatter从 bokeh.models导入："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import NumeralTickFormatter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "然后，在使用figure()函数创建绘图后，将 分配给 NumeralTickFormatter绘图formatter的属性yaxis："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "p.yaxis[0].formatter = NumeralTickFormatter(format=\"$0.00\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "代码展示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import NumeralTickFormatter # 导入\n",
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create new plot\n",
    "p = figure(\n",
    "    title=\"Tick formatter example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# format axes ticks\n",
    "p.yaxis[0].formatter = NumeralTickFormatter(format=\"$0.00\")\n",
    "p.xaxis[0].formatter = NumeralTickFormatter(format=\"$0.00\")\n",
    "\n",
    "# add renderers\n",
    "p.circle(x, y, size=8)\n",
    "p.line(x, y, color=\"navy\", line_width=1)\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 启用对数轴"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "y_axis_type=\"log\"切换到对数轴："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]\n",
    "y0 = [i**2 for i in x]\n",
    "y1 = [10**i for i in x]\n",
    "y2 = [10**(i**2) for i in x]\n",
    "\n",
    "# create a new plot with a logarithmic axis type\n",
    "p = figure(\n",
    "    title=\"Logarithmic axis example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    height=300,\n",
    "    max_width=500,\n",
    "    y_axis_type=\"log\",\n",
    "    y_range=[0.001, 10 ** 11],\n",
    "    x_axis_label=\"sections\",\n",
    "    y_axis_label=\"particles\",\n",
    ")\n",
    "\n",
    "# add some renderers\n",
    "p.line(x, x, legend_label=\"y=x\")\n",
    "p.circle(x, x, legend_label=\"y=x\", fill_color=\"white\", size=8)\n",
    "p.line(x, y0, legend_label=\"y=x^2\", line_width=3)\n",
    "p.line(x, y1, legend_label=\"y=10^x\", line_color=\"red\")\n",
    "p.circle(x, y1, legend_label=\"y=10^x\", fill_color=\"red\", line_color=\"red\", size=6)\n",
    "p.line(x, y2, legend_label=\"y=10^x^2\", line_color=\"orange\", line_dash=\"4 4\")\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 启用日期时间轴"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "设置x_axis_type或y_axis_type以datetime在轴上显示日期或时间信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用 DatetimeTickFormatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "from datetime import datetime, timedelta\n",
    "\n",
    "from bokeh.models import DatetimeTickFormatter, NumeralTickFormatter #引入\n",
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# generate list of dates (today's date in subsequent weeks)\n",
    "dates = [(datetime.now() + timedelta(day * 7)) for day in range(0, 26)]\n",
    "\n",
    "# generate 25 random data points\n",
    "y = random.sample(range(0, 100), 26)\n",
    "\n",
    "# create new plot\n",
    "p = figure(\n",
    "    title=\"datetime axis example\",\n",
    "    x_axis_type=\"datetime\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# add renderers\n",
    "p.circle(dates, y, size=8)\n",
    "p.line(dates, y, color=\"navy\", line_width=1)\n",
    "\n",
    "# format axes ticks\n",
    "p.yaxis[0].formatter = NumeralTickFormatter(format=\"$0.00\")\n",
    "p.xaxis[0].formatter = DatetimeTickFormatter(months=\"%b %Y\")\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义网格"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "设置对象的 xgrid()、 ygrid()和 grid()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 样式线"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "grid_line通过设置各种属性来更改网格的水平线和垂直线的外观"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a plot\n",
    "p = figure(\n",
    "    title=\"Customized grid lines example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# add a renderer\n",
    "p.line(x, y, line_color=\"green\", line_width=2)\n",
    "\n",
    "# change just some things about the x-grid\n",
    "p.xgrid.grid_line_color = \"red\"\n",
    "\n",
    "# change just some things about the y-grid\n",
    "p.ygrid.grid_line_alpha = 0.8 #设置网格透明度\n",
    "p.ygrid.grid_line_dash = [3, 5] #设置网格虚线（虚线每小节长度）\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 使用带和边界"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a plot\n",
    "p = figure(\n",
    "    title=\"Bands and bonds example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# add a renderer\n",
    "p.line(x, y, line_color=\"green\", line_width=2)\n",
    "\n",
    "# add bands to the y-grid\n",
    "p.ygrid.band_fill_color = \"olive\"\n",
    "p.ygrid.band_fill_alpha = 0.1\n",
    "\n",
    "# define vertical bonds\n",
    "p.xgrid.bounds = (1, 5)# 设置填充边界（x轴）\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 设置背景颜色"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "fill_color"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.plotting import figure, show\n",
    "\n",
    "# prepare some data\n",
    "x = [1, 2, 3, 4, 5]\n",
    "y = [4, 5, 5, 7, 2]\n",
    "\n",
    "# create a plot\n",
    "p = figure(\n",
    "    title=\"Background colors example\",\n",
    "    sizing_mode=\"stretch_width\",\n",
    "    max_width=500,\n",
    "    height=250,\n",
    ")\n",
    "\n",
    "# add a renderer\n",
    "p.line(x, y, line_color=\"green\", line_width=2)\n",
    "\n",
    "# change the fill colors\n",
    "p.background_fill_color = \"red\"\n",
    "p.border_fill_color = \"blue\"\n",
    "p.outline_line_color = \"orange\"\n",
    "\n",
    "# show the results\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
